/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Database.BazaDate;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Line2D;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author Reneul
 */
public class ViewDraw extends JPanel {

    public Dimension d;

    public ViewDraw(Dimension d) {
        this.d = d;
        this.setPreferredSize(d);
    }

    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;
        BazaDate bd = new BazaDate();
        bd.conecteaza();
        ResultSet rez;
        ResultSet rez1;
        ResultSet rez2;
        ResultSet rez3;
        try {
            rez = bd.doQuery("select * from statii");
            while (rez.next()) {
                //Line2D lin = new Line2D.Float(Integer.parseInt(rez.getString(3)), Integer.parseInt(rez.getString(4)), Integer.parseInt(rez.getString(3)), Integer.parseInt(rez.getString(4)));
                g2.drawOval(Integer.parseInt(rez.getString(3)) + 150, Integer.parseInt(rez.getString(4)) - 150, 2 * 2, 2 * 2);
                g2.setColor(Color.BLACK);
                g2.fillOval(Integer.parseInt(rez.getString(3)) + 150, Integer.parseInt(rez.getString(4)) - 150, 2 * 2, 2 * 2);
                //System.out.print(rez.getString(1) + " " + rez.getString(3) + " " + rez.getString(2) + "\n");
            }
            rez1 = bd.doQuery("select * from drumuri");
            while (rez1.next()) {
                rez2 = bd.doQuery("select * from statii where idStatie = "+rez1.getString("idStatie1"));
                rez3 = bd.doQuery("select * from statii where idStatie = "+rez1.getString("idStatie2"));
                rez2.next();rez3.next();
                //System.out.println(Integer.parseInt(rez2.getString(3)));
                Line2D lin = new Line2D.Float(Integer.parseInt(rez2.getString(3))+150, Integer.parseInt(rez2.getString(4))-150, Integer.parseInt(rez3.getString(3))+150, Integer.parseInt(rez3.getString(4))-150);
                g2.draw(lin);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ViewDraw.class.getName()).log(Level.SEVERE, null, ex);
        }

       
    }
}
